const { createStore } = require("redux")
const { ADD_NUMBER,CHANGE_NAME} = require("./constants")

//初始化store中的数据
const initialState = {
  name: "张三",
  counter: 100
}

function reducer(state = initialState, action) {
  switch (action.type) {
    case ADD_NUMBER:
      return {...state, name: action.name }
    case CHANGE_NAME:
      return {...state, counter: state.counter + action.counter}
    default:
      return state;
  }
}

//创建的store
const store = createStore(reducer);

module.exports = store;